//
//  HYBuyView.m
//  HaiYue
//
//  Created by skyline on 2018/1/25.
//  Copyright © 2018年 skyline. All rights reserved.
//

#import "HYBuyView.h"
#import "HYTradeHeaderView.h"
#import "HYReleaseSelectView.h"
#import "HYBuyGameCountTableView.h"
@interface HYBuyView ()<HYTradeHeaderViewDelegate,HYReleaseSelectViewDelegate,HYBuyGameCountTableViewDelegate>
@property (nonatomic, strong) HYTradeHeaderView *headerView;
@property (nonatomic, strong) HYBuyGameCountTableView *buyTableView;
@property (nonatomic, strong) HYReleaseSelectView *releaseView;
@end
@implementation HYBuyView
- (instancetype)init
{
    self = [super init];
    if (self)
    {
        self.headerView.hidden = NO;
        self.buyTableView.hidden = NO;
    }
    return self;
}

- (HYTradeHeaderView *)headerView
{
    if (!_headerView)
    {
        _headerView = [[HYTradeHeaderView alloc] init];
        _headerView.delegate = self;
        [self addSubview:_headerView];
        [_headerView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self);
            make.top.equalTo(self);
            make.size.mas_equalTo(CGSizeMake(SCREEN_WIDTH, ButtonHeight));
        }];
    }
    return _headerView;
}

- (HYBuyGameCountTableView *)buyTableView
{
    if (!_buyTableView)
    {
        _buyTableView = [[HYBuyGameCountTableView alloc] init];
        _buyTableView.hydelegate = self;
        [self addSubview:_buyTableView];
        [_buyTableView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.headerView.mas_bottom);
            make.left.equalTo(self);
            make.size.mas_equalTo(CGSizeMake(SCREEN_WIDTH, SCREEN_HEIGHT - NAVIBAR_HEIGHT - STATUS_HEIGHT - TABBAR_HEIGHT - ButtonHeight));
        }];
    }
    return _buyTableView;
}

- (HYReleaseSelectView *)releaseView
{
    if (!_releaseView)
    {
        _releaseView = [[HYReleaseSelectView alloc] init];
        _releaseView.delegate = self;
        [self addSubview:_releaseView];
        [_releaseView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.headerView.mas_bottom);
            make.left.equalTo(self);
            make.size.mas_equalTo(CGSizeMake(SCREEN_WIDTH, SCREEN_HEIGHT - NAVIBAR_HEIGHT - STATUS_HEIGHT - TABBAR_HEIGHT - ButtonHeight));
        }];
    }
    return _releaseView;
}

#pragma mark - HYTradeHeaderViewDelegate
- (void)methodForHYTradeHeaderViewDelegateWithTag:(NSInteger)tag
{
    if (tag == 201)
    {
        self.releaseView.hidden = (_releaseView)?NO:!self.releaseView.hidden;
    }
    else if(self.delegate && [self.delegate respondsToSelector:@selector(methodForHYBuyViewDelegateWithTag:)])
    {
        [self.delegate methodForHYBuyViewDelegateWithTag:tag];
    }
}

#pragma mark - HYReleaseSelectViewDelegate
- (void)methodForHYReleaseSelectViewDelegateWithTitle:(NSString *)title
{
    self.headerView.firstTitle = title;
}

#pragma mark  -  HYBuyGameCountTableViewDelegate
- (void)methodForHYBuyGameCountTableViewDelegateWithIndexPath:(NSIndexPath *)indexPath
{
    if (self.delegate && [self.delegate respondsToSelector:@selector(methodForHYBuyViewDelegateWithIndexPath:)])
    {
        [self.delegate methodForHYBuyViewDelegateWithIndexPath:indexPath];
    }
}
/*
 // Only override drawRect: if you perform custom drawing.
 // An empty implementation adversely affects performance during animation.
 - (void)drawRect:(CGRect)rect {
 // Drawing code
 }
 */

@end
